package com.fjzx.androidframe.ui.flow;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.fjzx.androidframe.ui.R;

/**
 * 基础过滤控件
 *
 * @author xiongyongcong
 */
public abstract class BaseFilterView extends ConstraintLayout implements View.OnClickListener {
    protected TextView btClear;
    protected TextView btSubmit;
    protected NestedScrollView clFilterContent;

    public BaseFilterView(Context context) {
        this(context, null);
    }

    public BaseFilterView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BaseFilterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.common_filter_view, this);
        btClear = findViewById(R.id.bt_clear);
        btSubmit = findViewById(R.id.bt_submit);
        clFilterContent = findViewById(R.id.filter_content);
        btClear.setOnClickListener(v -> onFilterClear());
        btSubmit.setOnClickListener(v -> onFilterSubmit());

        View filterView = inflater.inflate(bindFilterView(context), clFilterContent, false);
        clFilterContent.addView(filterView);
        initView(filterView);
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        initData();
    }

    @Override
    public void onClick(View v) {
    }

    protected abstract int bindFilterView(Context context);

    protected abstract void initView(View view);

    protected abstract void initData();

    protected abstract void onFilterSubmit();

    protected abstract void onFilterClear();
}
